feat: Add support for transaction status indicator (\T) in prompt#1553
Open
devadathanmb wants to merge 7 commits intodbcli:mainfrom
Open
feat: Add support for transaction status indicator (\T) in prompt#1553devadathanmb wants to merge 7 commits intodbcli:mainfrom
\T) in prompt#1553devadathanmb wants to merge 7 commits intodbcli:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for a transaction status indicator escape (\T) in the prompt, analogous to psql’s %x, so users can see transaction state directly in their prompt.
Changes:
- Introduces
PGExecute.transaction_indicator(andis_connection_closed) to derive a single-character transaction state marker (*,!,?, or empty). - Extends
PGCli.get_promptand the defaultpgclircconfiguration to support a new\Tprompt escape for transaction status. - Adds tests for
\Tprompt rendering and updatesAUTHORS.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
pgcli/pgexecute.py |
Adds is_connection_closed and the transaction_indicator property, reusing existing transaction status helpers to compute the * / ! / ? / empty marker. |
pgcli/main.py |
Extends get_prompt to replace \T with pgexecute.transaction_indicator, wiring the new indicator into prompt rendering. |
pgcli/pgclirc |
Documents the new \T prompt escape and its behavior alongside existing prompt placeholders. |
tests/test_main.py |
Adds tests covering \T in simple and full prompts; currently sets transaction_indicator via PropertyMock on MagicMock’s type, which mutates global MagicMock state. |
AUTHORS |
Adds a new contributor entry. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Use direct attribute assignment on MagicMock instead of type() to avoid polluting the global MagicMock class state.
Author
|
I’m not sure why this test is failing. It doesn’t appear to be related to the changes in this patch. The same patch passes all CI checks on my fork (see: https://github.com/devadathanmb/pgcli/actions/runs/21539731264?pr=2) Could you please rerun the actions? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds support for displaying transaction status in the prompt via the
\Tescape sequence, similar to psql's%xBehavior:
*— inside a valid transaction block!— inside a failed transaction block?— connection is closed/indeterminateExample usage in
~/.config/pgcli/config:This produces prompts like (as shown in the attached screenshot below):
NOTE: Uses
\Tinstead of\xto avoid conflicts with ANSI escape sequences (\x1b) processing done in the codebase.Closes #1552
Checklist
changelog.rst.AUTHORSfile (or it's already there).pip install pre-commit && pre-commit install).